﻿using System;
using System.Configuration;
using System.Linq;

namespace AspNetPaging
{
    public static class PagingManager
    {
        public static int[] Sizes;
        public static int Size;
        public static int Link;
        public static string Prev;
        public static string Next;
        public static string Template;

        static PagingManager()
        {
            var sizeConfig = GetAppConfig("paging:sizes", "10,20,30");
            Sizes = sizeConfig.Split(',').Select(o => Convert.ToInt32(o)).ToArray();
            var defaultSizeConfig = GetAppConfig("ping:size", "10");
            Size = Convert.ToInt32(defaultSizeConfig);
            var linkCountConfig = GetAppConfig("ping:link", "11");
            Link = Convert.ToInt32(linkCountConfig);
            Prev = GetAppConfig("paging:prev", "<");
            Next = GetAppConfig("paging:next", ">");
            Template = GetAppConfig("paging:template", null);
        }

        private static string GetAppConfig(string key, string defaultValue)
        {
            var value = ConfigurationManager.AppSettings[key];
            return string.IsNullOrEmpty(value) ? defaultValue : value;
        }
    }
}